using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Microsoft.EntityFrameworkCore;
using DataWasher.WebApi.Repositories.Base;
using DataWasher.WebApi.Repositories;
using DataWasher.WebApi.Services;
using DataWasher.WebApi.Interfaces;
using DataWasher.WebApi.Entities;
using ToolManager.Service;
using ToolManager.IService;
using ToolManager.Common;
using DataWasher.WebApi.IServices;
using DataWasher.WebApi.SqlServerRepositories;
using DataWasher.WebApi.EntitiesSQLServer;

namespace DataWasher.WebApi
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var sqlserverConnStr = Configuration.GetConnectionString("sqlserver");
            services.AddDbContext<SqlServerDBContext>(options => options.UseSqlServer(sqlserverConnStr));

            var mysqlConnStr = Configuration.GetConnectionString("mysql");
            services.AddDbContext<MyDbConetxt>(options => options.UseMySql(mysqlConnStr));



            #region register repository
            services.AddScoped(typeof(IRepositoryBase<>), typeof(RepositoryBase<>));
            services.AddScoped<IVmMntrRequrestRepository, VmMntrRequrestRepository>();
            services.AddScoped<IVmMntrRequestDetailRepository, VmMntrRequestDetailRepository>();
            services.AddScoped<ISysRelationRepository, SysRelationRepository>();
            services.AddScoped<ICostRecordRepository, CostRecordRepository>();
            services.AddScoped<ICostRecordExtraRepository, CostRecordExtraRepository>();
            services.AddScoped<ICalculateService, CalculateService>();
            services.AddScoped<IStoreInfoRepository, StoreInfoRepository>();
            services.AddScoped(typeof(ISqlserverRepositoryBase<>), typeof(SqlserverRepositoryBase<>));
            services.AddScoped<IDomainRepository, DomainRepository>();
            services.AddScoped<IStoreInfoRepository, StoreInfoRepository>();
            services.AddScoped<IBaseStoreBrandRepository, BaseStoreBrandRepository>();

            #endregion

            #region register services
            services.AddScoped<IDataExtractService, DataExtractService>();
            services.AddScoped<IStorageService, StorageService>();
            services.AddSingleton<ConnectionStrings>();
            services.AddScoped<IExtrackDataFromSqlServer, ExtrackDataFromSqlServer>();
            services.AddScoped<IExtrackDataFromSqlServer, ExtrackDataFromSqlServer>();
            #endregion
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
